package com.qf.shopemail.config;

import com.qf.common.constant.RabbitMqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    @Bean
    public FanoutExchange fanoutEmailExchange() {
        return new FanoutExchange(RabbitMqConstants.EMAIL_EXCHANGE, true, false);
    }

    @Bean
    public Queue queueEmail() {
        return new Queue(RabbitMqConstants.EMAIL_QUEUE, true, false, false);
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queueEmail()).to(fanoutEmailExchange());
    }
}
